#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
const int N=4e5+10,M=2e5+10;
mt19937 rnd(time(0));
int n;
vector<int>e[N];
int E,V,vis[N];
void dfs(int x)
{
	if(vis[x])return;
	vis[x]=1,V++;
	for ( auto v:e[x] )
		E++,dfs(v);
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("pairint.in","r",stdin);
	freopen("pairint.out","w",stdout);
	cin >> n;
	for ( int i = 1 ; i <= n ; i++ )
	{
		int u,v;cin >> u >> v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	int ans=0;
	for ( int i = 1 ; i <= 4e5 ; i++ )
	{
		if(vis[i])continue;
		E=V=0;dfs(i);E/=2;
		if(V>E)ans+=E;
		else ans+=V;
	}
	cout << ans;
	return 0;
}


